<?php
/**
 *	KLF Framework
 *
 *	Written by Kristian Oye <kristianoye@gmail.com> on Oct 24, 2011
 *	Copyright (C) 2010-2011
 */
namespace KLF\System\Web\Responses\Model
{
	use KLF\System\Errors\KException;
	use KLF\System\Data\Model\KBaseModel;
	
	/**
	 *  Class KExceptionModel
	 *
	 *  Data model for displaying information about an exception.
	 *
	 *  @package KLF\System\Web\Responses\Model
	 *  @access public
	 *  @author Kristian Oye <kristianoye@gmail.com>
	 *  @since 0.1
	 *  
	 *  @method KExceptionModel NewInstance
	 *  
	 *  @property KException $Exception
	 */
	class KExceptionModel extends KBaseModel
	{
		/**
		 * The exception contained within.
		 * 
		 * @var KException $_propException The error
		 */
		protected $_propException;
		
		public function __construct($exception = NULL)
		{
			$this->_propException = $exception;			
		}
		
		public function getLines()
		{
			$lines = explode("\n", file_get_contents($this->_propException->getFile()));
			$ret = array_slice($lines, $this->_propException->getLine() - 3, 5);
			
			for($i=$this->_propException->getLine() - 3,$n=0; $i < $this->_propException->getLine() + 2; $i++)
			{
				$l = $i + 1;
				if($l == $this->_propException->getLine())
				{
					$ret[$n++] = "<span style='color:red;'>Line $l:" . $lines[$i] . "</span>";
				}
				else
				{
					$ret[$n++] = "<span>Line $l:</span> " . $lines[$i];
				}
			}
			return $ret;
		}
	}
}
